﻿//获取cookie数据
function getCookie(name)
{
	var strArg=name+"=";
	var iArgLength=strArg.length;
	var iCookieLength=document.cookie.length;
	var iIndex=0;
	while(iIndex<iCookieLength)
	{
		var kIndex=iIndex+iArgLength;
		if(document.cookie.substring(iIndex,kIndex)==strArg) return getCookieVal(kIndex);
		iIndex=document.cookie.indexOf(" ",iIndex)+1;
		if(iIndex==0) break;
	}
	return null;
}

//截取cookie数据
function getCookieVal(offset)
{
	var iEndStr=document.cookie.indexOf(";",offset);
	if(iEndStr==-1)	iEndStr=document.cookie.length;
	return unescape(document.cookie.substring(offset,iEndStr));
}

//获取cookie键值
function getCookieValue(cookieStr,name)
{
	var cookieArr,i,pos;
	var temp;
	cookieStr=getCookie(cookieStr);
	cookieStr+="";
	if(cookieStr.length==0) return(null);
	if(name.length==0) return(cookieStr);
	cookieArr=cookieStr.split("&")
	for(i=0;i<cookieArr.length;i++){
		temp=cookieArr[i].toLowerCase();	
		if(name.toLowerCase() + "=" == temp.substr(0,name.length) + "=" ) {
			return(temp.substr(name.length+1));
		}
	}
}

/*-选取器-*/
function $F(str)
{
  if(typeof(document.getElementById(str))!="object")
   return null;
  else
   return document.getElementById(str);
}

/* 根据复选钮名字得到内容值*/
function $FN(str)
{
  if(typeof(document.getElementsByName(str))!="object")
    return "";
  else
  {
    var rstr="";
    var fnlist=document.getElementsByName(str);
    for(var i=0;i<fnlist.length;i++)
    {
      if(fnlist[i].checked)
      {
        if(rstr!="")
          rstr+=",";
        rstr+=fnlist[i].value;
      }
    }
    return rstr;
  }
}

/* -- 处理页面checkbox的全选与取消 -- */
function clientselect(obj)
{//debugger
 if(!obj.checked)
 {
  selectno();
 }
 else
 {
  selectall();
 }
}
function selectall()
{
   l=document.getElementsByTagName('input');
   for(i=0;i<l.length;i++)
  {
    if(l[i].type=='checkbox')
    {
       l[i].checked=true;
     }
   }
}
function selectno()
{
  l=document.getElementsByTagName('input');
  for(i=0;i<l.length;i++)
  {
    if(l[i].type=='checkbox')
    {
      l[i].checked=false;
    }
  }
}
 document.write('<iframe id=ifiledown frameborder=0 style=display:none;></iframe>');
function downloadfile(filetype,busstype,search)
{
 $F("ifiledown").src='../down.aspx?filetype='+filetype+'&buss='+busstype+'&search='+search+'';
}
/*-----order list go down------*/
function goUp(obj,cellnum){
	curRow = obj.parentElement.parentElement;
	var curLn = curRow.rowIndex;
	var lastLn = curRow.rowIndex - 1;

	if (curLn!=1){
		lastRow = obj.parentElement.parentElement.parentElement.rows[lastLn];
		for(var i=0;i<cellnum;i++){
			tmpHtml = curRow.cells[i].innerHTML;
			curRow.cells[i].innerHTML = lastRow.cells[i].innerHTML;
			lastRow.cells[i].innerHTML = tmpHtml;
		}
	}else{
		alert("Cannot move up");
	}
}

function goDown(obj,cellnum){
	totalRows = obj.parentElement.parentElement.parentElement.rows.length - 1;
	curRow = obj.parentElement.parentElement;
	var curLn = curRow.rowIndex;
	var lastLn = curRow.rowIndex + 1;

	if (totalRows != curLn) {
		lastRow = obj.parentElement.parentElement.parentElement.rows[lastLn]
		for(var i=0;i<cellnum;i++){
			tmpHtml = curRow.cells[i].innerHTML;
			curRow.cells[i].innerHTML = lastRow.cells[i].innerHTML;
			lastRow.cells[i].innerHTML = tmpHtml;
		}
	}else{
		alert("Cannot Move Down!");
	}
}

/* --表格内容修改和重置 --*/
function modify(obj,cellstart,cellend)
    {
      var crow=obj;
      var minwidth=50,maxwidth=200,stepwidth=20,cwidth=0;
      for(var i=cellstart;i<=cellend;i++)
      {
        var strtemp=crow.cells[i].innerHTML;
        if(strtemp.indexOf('<')==0)
         break;
        cwidth=stepwidth*strtemp.length;
        if(cwidth>maxwidth)
          cwidth=maxwidth;
        if(cwidth<minwidth)
          cwidth=minwidth;
        if(i==cellend)
           crow.cells[i].innerHTML="<input type=\"text\" name=\"r"+i+"\"  value=\""+strtemp+"\" class=\"text-line\" style=\"width:"+cwidth+"px;\"><input type=hidden value=\""+strtemp+"\"> <input type=button name=\"rs\" value=\"修改\" onclick=\"save(this,"+cellstart+","+cellend+");\" class=\"bttn\"> <input type=button name=\"rr\" value=\"放弃\" onclick=\"rowreset(this,"+cellstart+","+cellend+",'res');\"  class=\"bttn\">";
        else
          crow.cells[i].innerHTML="<input type=\"text\"  name=\"r"+i+"\"  value=\""+strtemp+"\" class=\"text-line\"  style=\"width:"+cwidth+"px;\"><input type=hidden value=\""+strtemp+"\">"; 
      }
    }
    function rowreset(obj,cellstart,cellend,types)
    {
      var crow=obj.parentElement.parentElement;
      for(var i=cellstart;i<=cellend;i++)
      {
        var strtemp="";
        if(types=="res")
         strtemp=crow.cells[i].childNodes[1].value;//reset
        else
         strtemp=crow.cells[i].childNodes[0].value; //修改
        crow.cells[i].innerHTML=strtemp;
      }
    }
/*酒店id*/
function gethid()
{
  return getCookieValue("cms","h");
}
function getpid()
{
  return getCookieValue("cms","p");
}
function getgid()
{
  return getCookieValue("cms","g");
}

function chkdate(str) {
    var re = /^[1,2]{1}\d{3}-[0-1]{0,1}[0-9]{1}-[0-3]{0,1}[0-9]{1}$/;
    if (re.test(str)) {
        var dateymd = str.split('-');
        var tempdate = new Date(dateymd[0], dateymd[1], dateymd[2]);
        if (tempdate > new Date(1901, 1, 1))
            return true;
        else
            return false;
     }
    else
        return false;
}

function $FDate(str)
{
  if(typeof(document.getElementById(str))!="object")
   return '';
  else
  {
    var dstr= document.getElementById(str).value;
    if(chkdate(dstr))
       return dstr;
    else
       return '';
   }
}



/*写页面帮助*/
function helpstep(types)
{
  var step=parseInt($F("helpboxstep").value);
  if(types=="n")
  {
   step++;
  }
  else
  {
   step--;
  }
  $F("helpboxstep").value=step;

  if(helpinfo.length>step && step>=0)
  {
    $F("showboxdetail").innerHTML=helpinfo[step];
    var navstr="";
    if(step>0)
    {
     navstr="<a href=\"#\" onclick=\"javascript:helpstep('p');\">上一步</a> &nbsp;";
    }
    if(step<helpinfo.length-1)
    {
     navstr+="<a href=\"#\" onclick=\"javascript:helpstep('n');\">下一步</a> &nbsp;";
    }
    $F("showboxnav").innerHTML=navstr;
  }
}

function closehelp()
{
  $F("helpboxpagecover").style.display='none';
  $F("helpbox").style.display='none';
}

